package com.xmy.solution.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xmy.common.annotation.Log;
import com.xmy.common.core.controller.BaseController;
import com.xmy.common.core.domain.AjaxResult;
import com.xmy.common.enums.BusinessType;
import com.xmy.solution.domain.MessagesDialog;
import com.xmy.solution.service.IMessagesDialogService;
import com.xmy.common.utils.poi.ExcelUtil;
import com.xmy.common.core.page.TableDataInfo;

/**
 * 对话框管理Controller
 * 
 * @author 夏明毅
 * @date 2025-02-18
 */
@RestController
@RequestMapping("/solution/dialog")
public class MessagesDialogController extends BaseController
{
    @Autowired
    private IMessagesDialogService messagesDialogService;

    /**
     * 查询对话框管理列表
     */
    @PreAuthorize("@ss.hasPermi('solution:dialog:list')")
    @GetMapping("/list")
    public TableDataInfo list(MessagesDialog messagesDialog)
    {
        startPage();
        List<MessagesDialog> list = messagesDialogService.selectMessagesDialogList(messagesDialog);
        return getDataTable(list);
    }
    @GetMapping("/AppList")
    public TableDataInfo list(@Param("type")Long type ,@Param("userId")Long userId)
    {
        startPage();
        MessagesDialog messagesDialog=new MessagesDialog();
        messagesDialog.setUserId(userId);
        messagesDialog.setMsgType(type);
        List<MessagesDialog> list = messagesDialogService.selectMessagesDialogList(messagesDialog);
        return getDataTable(list);
    }


    /**
     * 导出对话框管理列表
     */
    @PreAuthorize("@ss.hasPermi('solution:dialog:export')")
    @Log(title = "对话框管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MessagesDialog messagesDialog)
    {
        List<MessagesDialog> list = messagesDialogService.selectMessagesDialogList(messagesDialog);
        ExcelUtil<MessagesDialog> util = new ExcelUtil<MessagesDialog>(MessagesDialog.class);
        util.exportExcel(response, list, "对话框管理数据");
    }

    /**
     * 获取对话框管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('solution:dialog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(messagesDialogService.selectMessagesDialogById(id));
    }

    /**
     * 新增对话框管理
     */
    @PreAuthorize("@ss.hasPermi('solution:dialog:add')")
    @Log(title = "对话框管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MessagesDialog messagesDialog)
    {
        return toAjax(messagesDialogService.insertMessagesDialog(messagesDialog));
    }

    @PostMapping("/app")
    public AjaxResult AppAdd(@RequestBody MessagesDialog messagesDialog)
    {
        return toAjax(messagesDialogService.insertMessagesDialog(messagesDialog));
    }

    /**
     * 修改对话框管理
     */
    @PreAuthorize("@ss.hasPermi('solution:dialog:edit')")
    @Log(title = "对话框管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MessagesDialog messagesDialog)
    {
        return toAjax(messagesDialogService.updateMessagesDialog(messagesDialog));
    }

    /**
     * 删除对话框管理
     */
    @PreAuthorize("@ss.hasPermi('solution:dialog:remove')")
    @Log(title = "对话框管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(messagesDialogService.deleteMessagesDialogByIds(ids));
    }
}
